home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / CLIProtocol / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  7KB  |  299 lines

  1. /*
  2.  
  3.    XPR_External door.
  4.  
  5.    This door calls other pre-written CLS XPR transfer programs that use the
  6.    XPR<name>.library files.
  7.  
  8.    N_ND->ActiveDoor->SystemOptions
  9.    ===============================
  10.  
  11.    UPLOAD|DOWNLOAD
  12.  
  13.    dooroptions
  14.    ===========
  15.  
  16.    P=<xpr<lib>.library>
  17.  
  18.    D=<download path>       you should normally only specify one place and that should
  19.                              be HBBS:Nodes/NodeX/Playpen (or wherever the node's playpen is..)
  20.  
  21.    U=<file to upload>      you can specify more than one of these only if the protocol
  22.                              is a batch upload protocol
  23.                              e.g.
  24.                              U=dh2:warez/miggy/hotsoft.lha
  25.                              U=dh2:warez/miggy/newsoft.lha
  26.                              ....
  27.  
  28.  
  29.  
  30. */
  31.  
  32. #include <exec/types.h>
  33. #include <exec/memory.h>
  34. #include <dos/dos.h>
  35. #include <clib/exec_protos.h>
  36. #include <clib/dos_protos.h>
  37. #include <clib/alib_protos.h>
  38.  
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <stdio.h>
  42. #include <ctype.h>
  43. #include <time.h>
  44.  
  45. #include <libraries/xproto.h>  // XPR protocol stuff...
  46. #include <devices/serial.h>
  47. #include <devices/timer.h>
  48.  
  49. #ifdef __SASC
  50. int CXBRK(void) { return(0); }
  51. int _CXBRK(void) { return(0); }
  52. void chkabort(void) {}
  53. #endif
  54.  
  55. #include <HBBS/ANSI_Codes.h>
  56. #include <HBBS/Defines.h>
  57. #include <HBBS/types.h>
  58. #include <HBBS/structures.h>
  59. #include <HBBS/hbbscommon_protos.h>
  60. #include <HBBS/hbbscommon_pragmas.h>
  61. #include <HBBS/Hbbsnode_protos.h>
  62. #include <HBBS/Hbbsnode_pragmas.h>
  63. #include <HBBS/release.h>
  64. char *versionstr="$VER: CLIProtocol "RELEASE_STR;
  65.  
  66. long __stack=16384;
  67.  
  68. struct Library *HBBSCommonBase=NULL;
  69. struct Library *HBBSNodeBase=NULL;
  70.  
  71. struct BBSGlobalData *BBSGlobal=NULL;
  72. struct NodeData *N_ND=NULL;
  73. int N_NodeNum=-1;
  74.  
  75. struct List *ul_filelist=NULL;
  76. long ul_files=0;
  77. long currentul=1;
  78. struct List *dl_pathlist=NULL;
  79. long dl_paths=0;
  80.  
  81. struct CfgFileData *CfgFile=NULL;
  82.  
  83.  
  84. char *XE_Program=NULL;
  85. char *XE_Params=NULL;
  86. char *XE_SendStr=NULL;
  87. char *XE_RecvStr=NULL;
  88. V_BOOL XE_CDTODIR=TRUE;
  89.  
  90.  
  91. UBYTE *GetNodeStr(struct List *lh,ULONG n)
  92. {
  93.   struct Node *ln;
  94.  
  95.   for (ln = lh->lh_Head; n--; ln = ln->ln_Succ);
  96.   return (ln->ln_Name);
  97. }
  98.  
  99. static VOID cleanup(ULONG num)
  100. {
  101.   if (HBBSNodeBase)
  102.   {
  103.     HBBS_CleanUpDoor();
  104.     CloseLibrary (HBBSNodeBase);
  105.   }
  106.  
  107.   if (HBBSCommonBase)
  108.   {
  109.     HBBS_CleanUpCommon();
  110.     CloseLibrary (HBBSCommonBase);
  111.   }
  112.  
  113.   if (num) printf("Door Error = %d\n",num);
  114.  
  115.   exit(0);
  116. }
  117.  
  118. static VOID init(char *name)
  119. {
  120.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  121.   {
  122.     cleanup(1);
  123.   }
  124.  
  125.   if (!(HBBS_InitCommon()))
  126.   {
  127.     cleanup(2);
  128.   }
  129.  
  130.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  131.   {
  132.     cleanup(3);
  133.   }
  134.  
  135.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  136.   {
  137.     cleanup(4);
  138.   }
  139.   SetProgramName(name);
  140. }
  141.  
  142. void Xfer( void )
  143. {
  144.   char runstr[8192];
  145.   char tmpstr[4098];
  146.   LONG retval;
  147.   struct Node *node;
  148.  
  149.   BPTR FL,NFL;
  150.  
  151.   strcpy (runstr,XE_Program);
  152.   strcat (runstr," ");
  153.   strcat (runstr,XE_Params);
  154.  
  155.   if (ul_files>0)
  156.   {
  157.     replace(runstr,runstr,"{MODE}",XE_SendStr);
  158.   }
  159.   else
  160.   {
  161.     replace(runstr,runstr,"{MODE}",XE_RecvStr);
  162.     if (XE_CDTODIR)
  163.     {
  164.       if (FL=Lock(dl_pathlist->lh_Head->ln_Name,ACCESS_READ))
  165.       {
  166.         NFL=CurrentDir(FL);
  167.         UnLock(NFL);
  168.       }
  169.     }
  170.   }
  171.  
  172.   sprintf(tmpstr,"%d",N_ND->NodeDevice.SerialBaud);
  173.   replace(runstr,runstr,"{BAUD}",tmpstr);
  174.   sprintf(tmpstr,"%d",N_ND->NodeDevice.SerialUnit);
  175.   replace(runstr,runstr,"{UNIT}",tmpstr);
  176.   replace(runstr,runstr,"{DEVICE}",N_ND->NodeDevice.SerialDevice);
  177.  
  178.  
  179.   tmpstr[0]=0;
  180.  
  181.   if (ul_files>0)
  182.   {
  183.     for (node = ul_filelist->lh_Head ; node->ln_Succ ; node =node->ln_Succ)
  184.     {
  185.       if (node!=ul_filelist->lh_Head) strcat(tmpstr," ");
  186.       strcat(tmpstr,node->ln_Name);
  187.     }
  188.   }
  189.   else
  190.   {
  191.     for (node = dl_pathlist->lh_Head ; node->ln_Succ ; node =node->ln_Succ)
  192.     {
  193.       if (node!= dl_pathlist->lh_Head) strcat(tmpstr," ");
  194.       strcat(tmpstr,node->ln_Name);
  195.     }
  196.   }
  197.  
  198.   replace(runstr,runstr,"{FILES}",tmpstr);
  199.  
  200.   retval=HBBS_RunDOSCMD(runstr,FALSE);
  201.  
  202.   if ((N_ND->LoginType==LOGIN_REMOTE) && (CarrierLost()))
  203.   {
  204.     N_ND->OnlineStatus=OS_OFFLINE;
  205.   }
  206.  
  207.   sprintf(tmpstr,"%d",retval);
  208.   DOOR_Return(tmpstr);
  209. }
  210.  
  211. void DoorMain(int argc,char *argv[])
  212. {
  213.   int loop,p;
  214.   char outstr[1024];
  215.   BOOL Initialized=FALSE;
  216.  
  217.   if (ul_filelist=HBBS_CreateList())
  218.   {
  219.     if (dl_pathlist=HBBS_CreateList())
  220.     {
  221.       for(loop=3;loop<argc;loop++) // if there are any parameters then display them
  222.       {
  223.         switch(toupper(argv[loop][0]))
  224.         {
  225.           case 'U' :
  226.             if (NewStrNode(&argv[loop][2],ul_filelist)==ERR_NO_ERROR)
  227.             {
  228.               ul_files++;
  229.             }
  230.             break;
  231.           case 'D' :
  232.             if (NewStrNode(&argv[loop][2],dl_pathlist)==ERR_NO_ERROR)
  233.             {
  234.               dl_paths++;
  235.             }
  236.             break;
  237.           default:
  238.             DOOR_WriteText("Unknown Option Specified!\r\n");
  239.             break;
  240.         }
  241.       }
  242.  
  243.       strcpy(outstr,argv[0]);
  244.       if ((p=iposition(".HBBS",outstr))==(strlen(outstr)-5))
  245.       {
  246.         outstr[p]=0; //terminate string
  247.       }
  248.       strcat(outstr,"_");
  249.       strcat(outstr,argv[2]); //config number/string
  250.       strcat(outstr,".CFG");
  251.  
  252.       if (CfgFile=HBBS_LoadConfig(outstr,LCFG_NONE))
  253.       {
  254.         if (HBBS_GetSetting(CfgFile,(void *)&XE_Program,VTYPE_STRING,"Program",OPT_SINGLE) &&
  255.             HBBS_GetSetting(CfgFile,(void *)&XE_Params,VTYPE_STRING,"Params",OPT_SINGLE))
  256.         {
  257.           HBBS_GetSetting(CfgFile,(void *)&XE_SendStr,VTYPE_STRING,"SendStr",OPT_SINGLE);
  258.           HBBS_GetSetting(CfgFile,(void *)&XE_RecvStr,VTYPE_STRING,"RecvStr",OPT_SINGLE);
  259.           HBBS_GetSetting(CfgFile,(void *)&XE_CDTODIR,VTYPE_BOOL,"CDToDir",OPT_SINGLE);
  260.           if ((ul_files || dl_paths))
  261.           {
  262.             Initialized=TRUE;
  263.  
  264.             Xfer();
  265.           }
  266.         }
  267.         else
  268.         {
  269.           DOOR_WriteText("\r\nConfig File Error\r\n");
  270.         }
  271.         HBBS_FlushConfig(CfgFile);
  272.       }
  273.       FreeStrList(dl_pathlist);
  274.     }
  275.     FreeStrList(ul_filelist);
  276.   }
  277.   if (!Initialized) DOOR_WriteText(" Failed - Check Parameters!\r\n");
  278.  
  279. }
  280.  
  281. int main(int argc,char *argv[])
  282. {
  283.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  284.   {
  285.     printf("Invalid/No Paramaters for door!\n");
  286.     exit (20);
  287.   }
  288.   init("CLIProtocol");
  289.  
  290.   if (BBSGlobal=HBBS_GimmeBBS())
  291.   {
  292.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  293.     {
  294.       DoorMain(argc,argv);
  295.     }
  296.   }
  297.   cleanup(0);
  298. }
  299.